﻿<%@ Page Language="C#" MasterPageFile="../main.master" Inherits="VioletDevelopmentLaboratory.Net.Web.Configuration.VWebConfigManagerPage" %>

<script runat="server">
	protected void AuthorizationDetailsView_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
	{
		ShowAlert_DetailsView_ItemInserted(e);

		AuthorizationGridView.SelectedIndex = -1;
		AuthorizationGridView.DataBind();
	}

	protected void AuthorizationDetailsView_ItemUpdated(object sender, DetailsViewUpdatedEventArgs e)
	{
		ShowAlert_DetailsView_ItemUpdated(e);

		AuthorizationGridView.SelectedIndex = -1;
		AuthorizationGridView.DataBind();
	}

	protected void AuthorizationDetailsView_ItemDeleted(object sender, DetailsViewDeletedEventArgs e)
	{
		ShowAlert_DetailsView_ItemDeleted(e);

		AuthorizationDetailsView.ChangeMode(DetailsViewMode.Insert);
		
		AuthorizationGridView.SelectedIndex = -1;
		AuthorizationGridView.DataBind();
	}







	protected void AuthorizationGridView_RowDataBound(object sender, GridViewRowEventArgs e)
	{
		if (e.Row.RowType == DataControlRowType.DataRow)
		{
			((Label)e.Row.FindControl("IndexLabel")).Text = e.Row.RowIndex + "";
		}
	}
	protected void AuthorizationGridView_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
	{
		AuthorizationDetailsView.ChangeMode(DetailsViewMode.ReadOnly);
	}
	protected void Page_PreRender(object sender, EventArgs e)
	{
		AuthorizationGridView.Rows[AuthorizationGridView.Rows.Count - 1].Enabled = false;
	}
</script>

<asp:Content ID="Content1" ContentPlaceHolderID="BodyContentPlaceHolder" runat="server">

	<h2>Authorization</h2>

	<div>
		<fieldset>
			<asp:ObjectDataSource ID="AuthorizationDetailsViewDataSource" runat="server" 
				DeleteMethod="Remove" InsertMethod="Add" SelectMethod="GetRule" 
				TypeName="VioletDevelopmentLaboratory.Net.Web.Configuration.AuthorizationSectionManager" 
				UpdateMethod="Modify">
				<DeleteParameters>
					<asp:ControlParameter ControlID="AuthorizationGridView" Name="index" 
						PropertyName="SelectedIndex" Type="Int32" />
				</DeleteParameters>
				<UpdateParameters>
					<asp:ControlParameter ControlID="AuthorizationGridView" Name="index" 
						PropertyName="SelectedIndex" Type="Int32" />
					<asp:Parameter Name="action" Type="Object" />
					<asp:Parameter Name="roles" Type="String" />
					<asp:Parameter Name="users" Type="String" />
					<asp:Parameter Name="verbs" Type="String" />
				</UpdateParameters>
				<SelectParameters>
					<asp:ControlParameter ControlID="AuthorizationGridView" Name="index" 
						PropertyName="SelectedIndex" Type="Int32" />
				</SelectParameters>
				<InsertParameters>
					<asp:Parameter Name="index" Type="Int32" />
					<asp:Parameter Name="action" Type="Object" />
					<asp:Parameter Name="roles" Type="String" />
					<asp:Parameter Name="users" Type="String" />
					<asp:Parameter Name="verbs" Type="String" />
				</InsertParameters>
			</asp:ObjectDataSource>
			<asp:ObjectDataSource ID="AuthorizationGridViewDataSource" runat="server" 
				SelectMethod="GetRuleCollection" 
				
				TypeName="VioletDevelopmentLaboratory.Net.Web.Configuration.AuthorizationSectionManager">
			</asp:ObjectDataSource>
			<asp:DetailsView ID="AuthorizationDetailsView" runat="server" 
				AutoGenerateRows="False" CellPadding="5" 
				DataSourceID="AuthorizationDetailsViewDataSource" DefaultMode="Insert" 
				oniteminserted="AuthorizationDetailsView_ItemInserted" 
				onitemupdated="AuthorizationDetailsView_ItemUpdated" 
				onitemdeleted="AuthorizationDetailsView_ItemDeleted">
				<Fields>
					<asp:TemplateField HeaderText="Index">
						<InsertItemTemplate>
							<asp:TextBox ID="IndexTextBox" runat="server" Text='<%# Bind("Index") %>' />
						</InsertItemTemplate>
					</asp:TemplateField>
					<asp:TemplateField HeaderText="Action">
						<ItemTemplate>
							<asp:Label ID="ActionLabel" runat="server" Text='<%# Eval("Action") %>' />
						</ItemTemplate>
						<InsertItemTemplate>
							<asp:DropDownList ID="ActionDropDownList" runat="server"
								SelectedValue='<%# Bind("Action") %>'>
								<asp:ListItem>Allow</asp:ListItem>
								<asp:ListItem>Deny</asp:ListItem>
							</asp:DropDownList>
						</InsertItemTemplate>
						<EditItemTemplate>
							<asp:DropDownList ID="ActionDropDownList" runat="server"
								SelectedValue='<%# Bind("Action") %>'>
								<asp:ListItem>Allow</asp:ListItem>
								<asp:ListItem>Deny</asp:ListItem>
							</asp:DropDownList>
						</EditItemTemplate>
					</asp:TemplateField>
					<asp:TemplateField HeaderText="Roles">
						<ItemTemplate>
							<asp:Label ID="RolesLabel" runat="server" Text='<%# Eval("Roles") %>' />
						</ItemTemplate>
						<InsertItemTemplate>
							<asp:TextBox ID="RolesTextBox" runat="server" Text='<%# Bind("Roles") %>' />
						</InsertItemTemplate>
						<EditItemTemplate>
							<asp:TextBox ID="RolesTextBox" runat="server" Text='<%# Bind("Roles") %>' />
						</EditItemTemplate>
					</asp:TemplateField>
					<asp:TemplateField HeaderText="Users">
						<ItemTemplate>
							<asp:Label ID="UsersLabel" runat="server" Text='<%# Eval("Users") %>' />
						</ItemTemplate>
						<InsertItemTemplate>
							<asp:TextBox ID="UsersTextBox" runat="server" Text='<%# Bind("Users") %>' />
						</InsertItemTemplate>
						<EditItemTemplate>
							<asp:TextBox ID="UsersTextBox" runat="server" Text='<%# Bind("Users") %>' />
						</EditItemTemplate>
					</asp:TemplateField>
					<asp:TemplateField HeaderText="Verbs">
						<ItemTemplate>
							<asp:Label ID="VerbsLabel" runat="server" Text='<%# Eval("Verbs") %>' />
						</ItemTemplate>
						<InsertItemTemplate>
							<asp:TextBox ID="VerbsTextBox" runat="server" Text='<%# Bind("Verbs") %>' />
						</InsertItemTemplate>
						<EditItemTemplate>
							<asp:TextBox ID="VerbsTextBox" runat="server" Text='<%# Bind("Verbs") %>' />
						</EditItemTemplate>
					</asp:TemplateField>
					<asp:CommandField ButtonType="Button" ShowDeleteButton="True" 
						ShowEditButton="True" ShowInsertButton="True" />
				</Fields>
			</asp:DetailsView>
			<asp:GridView ID="AuthorizationGridView" runat="server" AutoGenerateColumns="False" 
				DataSourceID="AuthorizationGridViewDataSource" CellPadding="5" 
				onrowdatabound="AuthorizationGridView_RowDataBound" 
				onselectedindexchanging="AuthorizationGridView_SelectedIndexChanging">
				<Columns>
					<asp:CommandField ShowSelectButton="True" />
					<asp:TemplateField HeaderText="Index">
						<ItemTemplate>
							<asp:Label ID="IndexLabel" runat="server" />
						</ItemTemplate>
					</asp:TemplateField>
					<asp:BoundField DataField="Action" HeaderText="Action" 
						SortExpression="Action" />
					<asp:TemplateField HeaderText="Roles">
						<ItemTemplate>
							<asp:Label ID="RolesLabel" runat="server" Text='<%# Bind("Roles") %>' />
						</ItemTemplate>
					</asp:TemplateField>
					<asp:TemplateField HeaderText="Users">
						<ItemTemplate>
							<asp:Label ID="UsersLabel" runat="server" Text='<%# Bind("Users") %>' />
						</ItemTemplate>
					</asp:TemplateField>
					<asp:TemplateField HeaderText="Verbs">
						<ItemTemplate>
							<asp:Label ID="VerbsLabel" runat="server" Text='<%# Bind("Verbs") %>' />
						</ItemTemplate>
					</asp:TemplateField>
				</Columns>
				<SelectedRowStyle BackColor="SkyBlue" />
			</asp:GridView>
		</fieldset>
	</div>
</asp:Content>